package com.sp.system.user.core.aop;

import com.sp.system.user.core.annotation.LoginAuthentication;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 *  切面拦截 spring 托管定义组件
 */
@Component
@Slf4j
@Aspect
public class SpAspect {

//    private final String POINT_CUT = "execution(* com.sp..controller..*.*(..))";
    private final String POINT_CUT = "execution(* com.tfkj.cms..controller..*.*(..))";


    /**
     *  定义切点
     */
    @Pointcut(POINT_CUT)
    public void pointCut(){

        log.debug("pointCut");
    }

    /**
     * 切点前 执行
     * @param joinPoint
     */
    @Before(value = "pointCut()")
    public void beforeExecution(JoinPoint joinPoint){
//        log.debug("beforeExecution");
    }


    /**
     *
     * @param proceedingJoinPoint
     * @return
     */
    @Around(value = "pointCut() && @annotation(loginAuthentication)")
    public Object doAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, LoginAuthentication loginAuthentication) throws Throwable {

        log.debug("1" + loginAuthentication);

        return proceedingJoinPoint.proceed();
    }
    /**
     * 在切点方法之后执行
     * @param joinPoint
     */
    @After(value = "pointCut()")
    public void afterExecution(JoinPoint joinPoint){
//        log.debug("afterExecution");
    }
}
